/**
* 左边菜单
*/ 
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router  unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span>{{menu.menuname}}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
          <i class="iconfont" :class="chmenu.icon"></i>
          <span>{{chmenu.menuname}}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>
import { menu } from '../api/userMG'
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: []
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    // 获取图形验证码
    let res = {
      success: true,
      data: [
        {
          menuid: 1,
          icon: 'li-icon-xiangmuguanli',
          menuname: '首页',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 11,
              icon: 'icon-cat-skuQuery',
              menuname: '控制台子菜单1',
              hasThird: 'N',
              url: 'control/test',
              menus: null
            }
          ]
        },
        {
          menuid: 2,
          icon: 'li-icon-xiangmuguanli',
          menuname: '信息统计',
          hasThird: null,
          url: null,
          menus: [
            
            {
              menuid: 21,
              icon: 'icon-cat-skuQuery',
              menuname: '用户信息',
              hasThird: 'N',
              url: 'information/UserInf',
              menus: null
            },
             {
              menuid: 22,
              icon: 'icon-cat-skuQuery',
              menuname: '用户信息',
              hasThird: 'N',
              url: 'information/Userupdate',
              menus: null
            }
          ]
        },
        {
          menuid: 3,
          icon: 'li-icon-dingdanguanli',
          menuname: '商户管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 31,
              icon: 'icon-order-manage',
              menuname: '商户审批',
              hasThird: 'N',
              url: 'business/manage',
              menus: null
            }
          ]
        },
        {
          menuid: 4,
          icon: 'li-icon-dingdanguanli',
          menuname: '活动管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 41,
              icon: 'icon-order-manage',

              menuname: '活动管理',

//               menuname: '活动发布',
// >>>>>>> 015b763700d209fde0c46b924d31e1bbba81e2a8
              hasThird: 'N',
              url: 'activity/approval',
              menus: null
            }
          ]
        },
        {
          menuid: 5,
          icon: 'li-icon-dingdanguanli',
          menuname: '动态管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 51,
              icon: 'icon-order-manage',
              menuname: '活动态管理子菜单1',
              hasThird: 'N',
              url: 'dynamic/test',
              menus: null
            }
          ]
        },
        {
          menuid: 6,
          icon: 'li-icon-dingdanguanli',
          menuname: '投诉管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 61,
              icon: 'icon-order-manage',
              menuname: '物业投诉管理',
              hasThird: 'N',
              url: 'complaint/manage',
              menus: null
            },
             {
              menuid: 62,
              icon: 'icon-order-manage',
              menuname: '投诉添加测试',
              hasThird: 'N',
              url: 'complaint/add',
              menus: null
            },
            //  {
            //   menuid: 63,
            //   icon: 'icon-order-manage',
            //   menuname: '投诉添加测试2',
            //   hasThird: 'N',
            //   url: 'complaint/test',
            //   menus: null
            // },
            // {
            //   menuid: 64,
            //   icon: 'icon-order-manage',
            //   menuname: '投诉管理列表-商家查看用户投诉',
            //   hasThird: 'N',
            //   url: 'complaint/business',
            //   hidden:true,
            //   menus: null
            // },
            //  {
            //   menuid: 65,
            //   icon: 'icon-order-manage',
            //   menuname: '投诉管理列表-商家投诉平台',
            //   hasThird: 'N',
            //   url: 'complaint/addBusiness',
            //   hidden:true,
            //   menus: null
            // },
              {
              menuid: 66,
              icon: 'icon-order-manage',
              menuname: '商家-我的投诉列表',
              hasThird: 'N',
              url: 'complaint/lookBusiness',
              menus: null
            },
             {
              menuid: 67,
              icon: 'icon-order-manage',
              menuname: '平台投诉管理',
              hasThird: 'N',
              url: 'complaint/platform',
              menus: null
            }
          ]
        },
        {
          menuid: 7,
          icon: 'li-icon-xitongguanli',
          menuname: '收费管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 71,
              icon: 'icon-cus-manage',
              menuname: '收费管理子菜单1',
              hasThird: 'N',
              url: 'toll/test',
              menus: null
            }
            // {
            //   menuid: 174,
            //   icon: 'icon-cms-manage',
            //   menuname: '菜单管理',
            //   hasThird: 'N',
            //   url: 'system/Module',
            //   menus: null
            // },
            // {
            //   menuid: 73,
            //   icon: 'icon-news-manage',
            //   menuname: '角色管理',
            //   hasThird: 'N',
            //   url: 'system/Role',
            //   menus: null
            // },
            // {
            //   menuid: 74,
            //   icon: 'icon-cs-manage',
            //   menuname: '公司管理',
            //   hasThird: 'N',
            //   url: 'system/Dept',
            //   menus: null
            // },
            // {
            //   menuid: 75,
            //   icon: 'icon-promotion-manage',
            //   menuname: '系统环境变量',
            //   hasThird: 'N',
            //   url: 'system/Variable',
            //   menus: null
            // },
            // {
            //   menuid: 76,
            //   icon: 'icon-cms-manage',
            //   menuname: '权限管理',
            //   hasThird: 'N',
            //   url: 'system/Permission',
            //   menus: null
            // }
          ]
        },
        {
          menuid: 8,
          icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
          menuname: '物业管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 81,
              icon: 'icon-provider-manage',
              menuname: '物业管理子菜单1',
              hasThird: 'N',
              url: 'property/test',
              menus: null
            }
          
          ]
        },
        {
          menuid: 9,
          icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
          menuname: '权限管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 91,
              icon: 'icon-provider-manage',
              menuname: '角色管理',
              hasThird: 'N',
              url: 'permission/rolemanager',
              menus: null
            }
          
          ]
        },
        {
          menuid: 10,
          icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
          menuname: '系统管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 101,
              icon: 'icon-provider-manage',
              menuname: '系统管理子菜单1',
              hasThird: 'N',
              url: 'system/test',
              menus: null
            }
          
          ]
        },
        // {
        //   menuid: 10,
        //   icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
        //   menuname: '图表',
        //   hasThird: null,
        //   url: null,
        //   menus: [
        //     {
        //       menuid: 159,
        //       icon: 'icon-provider-manage',
        //       menuname: '数据可视化',
        //       hasThird: 'N',
        //       url: 'charts/statistics',
        //       menus: null
        //     }
        //   ]
        // }
      ],
      msg: 'success'
    }
    // this.$axios("/api/menu/findAll").then(res=>{
    //     this.allmenu=res.data.data
    //   }).catch();
    //模拟数据
          // this.allmenu = res.data

    //连接后端，注释上面一行，解开下面代码
    this.$axios.get('api/rolepermmenu/menu/findByToken').
    then(res => {
        console.log("获取菜单"+res)
        if (res.data.code == 200) {
          this.allmenu = res.data.data
          console.log(this.allmenu)
        } else {
          //this.$message.error(res.data.msg)
          return false
        }
      })
      .catch(err => {
        this.$message.error('菜单加载失败，请稍后再试！')
      })


    // menu(localStorage.getItem('logintoken'))
    //   .then(res => {
    //     console.log(JSON.stringify(res))
    //     if (res.success) {
    //       this.allmenu = res.data
    //     } else {
    //       this.$message.error(res.msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #1f2d3d !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  height: 40px;
}
</style>